package cn.wqb.wallet.entity;

public class Result {

    public final static int Code_Success = 0;
    public final static int Code_Fail = 1;

    private int code;
    private String msg;
    private Object data;
    private String sign;

    public static Result success(Object data) {
        return success(data, "");
    }

    public static Result success(Object data, String sign) {
        Result result = new Result();
        result.code = Code_Success;
        result.data = data;
        result.sign = sign;
        return result;
    }

    public static Result fail(String msg) {
        return fail(msg, Code_Fail);
    }

    public static Result fail(String msg, int failCode) {
        return fail(msg, failCode, null);
    }

    public static Result fail(String msg, int failCode, Object data) {
        Result result = new Result();
        result.code = failCode;
        result.msg = msg;
        result.data = data;
        return result;
    }

    private Result() {
    }

    public boolean isSuccess() {
        return code == Code_Success;
    }

    public boolean isFail() {
        return code != Code_Success;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                ", sign='" + sign + '\'' +
                '}';
    }

}
